package com.csu.jpetstore_reconfiguration_back.Controller;

import com.csu.jpetstore_reconfiguration_back.common.CommonResponse;
import com.csu.jpetstore_reconfiguration_back.domain.Order;
import com.csu.jpetstore_reconfiguration_back.domain.Product;
import com.csu.jpetstore_reconfiguration_back.mapper.ProductMapper;
import com.csu.jpetstore_reconfiguration_back.service.OrderService;
import com.csu.jpetstore_reconfiguration_back.service.ProductService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ProductController {
    @Resource
    private ProductService productService;

    //获取所有产品
    @GetMapping("/product")
    public CommonResponse<List<Product>> getAllProducts()
    {
        return productService.getAllProducts();
    }

    //获取单个产品
    @GetMapping("/product/{id}")
    public CommonResponse<Product> getProduct(@PathVariable String id)
    {
        return productService.getProduct(id);
    }

    //添加产品
    @PostMapping("/product")
    public CommonResponse<Product> addProduct(@Validated @RequestBody Product product)
    {
        return productService.addProduct(product);
    }

    //更新产品
    @PostMapping("/product/{id}")
    public CommonResponse<Product> updateProduct(@PathVariable String id, @Validated @RequestBody Product product)
    {
        return productService.updateProduct(id,product);
    }

    //删除产品
    @PostMapping("/product/{id}/delete")
    public CommonResponse<Product> deleteProduct(@PathVariable String id)
    {
        return productService.deleteProduct(id);
    }
}
